﻿<Window x:Class="MvvmLight1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:my="clr-namespace:System;assembly=mscorlib"
        xmlns:me="clr-namespace:MvvmLight1"
        mc:Ignorable="d"
        Height="520"
        Width="600"
        Title="MVVM Light Media Player Application"
        DataContext="{Binding Main, Source={StaticResource Locator}}" 
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras">
    
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/MainSkin.xaml" />
                <ResourceDictionary Source="Resources/GlassButton.xaml"/>
                <ResourceDictionary Source="Resources/MyThumbnailButton.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <!-- Disable the Selected item Highlight color -->
            <Style TargetType="ListViewItem">
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#00000000"/>
                    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#00000000"/>
                </Style.Resources>
            </Style>
        </ResourceDictionary>
    </Window.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <me:ObjectToVisibilityConverter x:Key="OVConverter"></me:ObjectToVisibilityConverter>
            <me:PlayerStatusToVisibilityConverter x:Key="PSVConverter"></me:PlayerStatusToVisibilityConverter>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="15"></RowDefinition>
            <RowDefinition Height="6*"></RowDefinition>
            <RowDefinition Height="50"></RowDefinition>
            <RowDefinition Height="150"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="50"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <Border Grid.Column="1" Grid.Row="1"  CornerRadius="5" BorderThickness="3" BorderBrush="Black" Background="Transparent">
            <me:MyPlayer x:Name="MediaEl" Source="{Binding MyVideoPath}" Stretch="UniformToFill" Volume="{Binding MediaVolume, Mode=TwoWay}"
                         Status="{Binding VideoStatus, Mode=TwoWay}"  MediaOpened="MediaEL_MediaOpen">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SizeChanged">
                        <cmd:EventToCommand Command="{Binding HeightCommand, Mode=OneWay}"
                                            CommandParameter="{Binding ElementName=MediaEl, Path=ActualHeight}"/>
                        <!--<cmd:EventToCommand Command="{Binding WidthCommand, Mode=OneWay}"
                                            CommandParameter="{Binding ElementName=MediaEl, Path=ActualWidth}"/>-->
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </me:MyPlayer>
        </Border>
        <me:BannerUserControl BannerString="{Binding BannerContent}" BannerSource="{Binding BannerImage}"
                              Grid.Column="1" Grid.Row="1" x:Name="BannersController" 
                              Visibility="{Binding BannerVisibility}" Height="{Binding BannerHeight}" 
                              Width="{Binding ElementName=MediaEl, Path=ActualWidth}" >
        </me:BannerUserControl>
        <!--<me:CircularProgressBar Height="100" Width="100" RotationsPerMinute="120" Grid.Column="1" Grid.Row="1" x:Name="CircularPB" 
                                Visibility="{Binding CircularProgressBarVisibility}"></me:CircularProgressBar>-->
        <StackPanel Grid.Column="1" Grid.Row="2"  HorizontalAlignment="Center" Orientation="Horizontal" 
                    Margin="2,2" VerticalAlignment="Center" Selector.IsSelected="False">
            <Button Cursor="Hand" Height="40" x:Name="btnPlay" Width="50" Command="{Binding SetStatusCommand}" Background="#FF660707"
                    CommandParameter="{Binding ElementName=btnPlay, Path=Content}" Style="{StaticResource GlassButton}" 
                    IsEnabled="{Binding MyVideoPath, Converter={StaticResource OVConverter}}" Content="{Binding PlayPauseButtonContent}"
                    Foreground="AntiqueWhite" FontWeight="Bold">
            </Button>
            <Slider Cursor="Hand" Height="22" Width="250" Minimum="0" Maximum="1"  x:Name="sliderPosition" AutoToolTipPlacement="TopLeft"
                    Thumb.DragStarted="sliderPosition_DragStarted" Thumb.DragCompleted="sliderPosition_DragCompleted" AutoToolTipPrecision="1"
                    IsEnabled="{Binding VideoStatus, Converter={StaticResource PSVConverter}}" Margin="15,2"></Slider>
            <Button Cursor="Hand" Height="40" x:Name="btnStop" Width="50" Command="{Binding SetStatusCommand}" Content="{Binding StopButtonContent}"
                    CommandParameter="{Binding ElementName=btnStop, Path=Content}" Style="{StaticResource GlassButton}"
                    IsEnabled="{Binding VideoStatus, Converter={StaticResource PSVConverter}}" Foreground="AntiqueWhite"
                    Background="Black" FontWeight="Bold">
            </Button>
        </StackPanel>

        <ListView Grid.Row="4" Margin="2" ScrollViewer.HorizontalScrollBarVisibility="Auto" Background="LightCyan" 
                  ScrollViewer.VerticalScrollBarVisibility="Disabled" x:Name="ThumbnailListView" Grid.Column="0" Grid.ColumnSpan="3"
                  ItemsSource="{Binding Source={StaticResource Locator}, Path=Main.Thumbnails}" SnapsToDevicePixels="True"
                  VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel x:Name="mediaContainer" Orientation="Horizontal"></WrapPanel>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Button Template="{StaticResource ThumbnailButton}" ToolTip="{Binding name}" Margin="3,5,3,3"
                            ToolTipService.HasDropShadow="True" ToolTipService.Placement="RelativePoint"
                            Width="170" Height="115" Command="{Binding Source={StaticResource Locator}, Path=Main.ImageCommand}" 
                            CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ListViewItem}}" />
                    <!--<Border Name="mask" Background="White" BorderBrush="BurlyWood" BorderThickness="4" CornerRadius="3" Margin="1,4,4,6"
                            me:MyHoverBehavior.HoverBehavior="True">
                        <Grid>
                            <Image Cursor="Hand" Source="{Binding imageUrl}" ToolTip="{Binding name}" Stretch="Uniform"
                                    ToolTipService.HasDropShadow="True" ToolTipService.Placement="RelativePoint" ClipToBounds="True">
                            </Image>
                        </Grid>
                        <Border.Effect>
                            <DropShadowEffect/>
                        </Border.Effect>
                    </Border>-->
                </DataTemplate>
            </ListView.ItemTemplate>
            <!--<i:Interaction.Triggers>
                <i:EventTrigger EventName="PreviewMouseLeftButtonDown">
                    <i:InvokeCommandAction Command="{Binding ImageCommand, Mode=OneWay}"
                                        CommandParameter="{Binding ElementName=ThumbnailListView, Path=SelectedItem}"/>
                    <cmd:EventToCommand Command="{Binding ImageCommand, Mode=OneWay}"
                                        CommandParameter="{Binding ElementName=ThumbnailListView, Path=SelectedItem}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>-->
        </ListView>
        <TextBlock Grid.Row="0" Grid.Column="1" FontSize="11"
                   FontWeight="Bold"
                   Foreground="Purple"
                   Text="{Binding Welcome}"
                   VerticalAlignment="Center"
                   HorizontalAlignment="Center"
                   TextWrapping="Wrap" />
        <WrapPanel Grid.Column="0" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Vertical">
            <Border Name="mask" Background="White" BorderBrush="Black" BorderThickness="2" CornerRadius="8" Padding="2" Margin="5,0,5,5">
                <Image x:Name="soundImg" Source="{Binding SoundImageSource}" Width="30" Height="30" Tag="{Binding TagImageSound}"
                        Cursor="Hand" Stretch="UniformToFill">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseDown">
                            <cmd:EventToCommand Command="{Binding SoundImageCommand, Mode=OneWay}"
                                                                CommandParameter="{Binding ElementName=soundImg, Path=Tag}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Image>
            </Border>
            <Slider Height="93" Orientation="Vertical" HorizontalAlignment="Center" Minimum="0" Maximum="1" Cursor="Hand"
                    Name="slider1" Width="22" Value="{Binding ElementName=MediaEl, Path=Volume}" VerticalAlignment="Center"
                    IsEnabled="{Binding VideoStatus, Converter={StaticResource PSVConverter}}"/>
        </WrapPanel>
    </Grid>
</Window>
